using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerMover : MonoBehaviour
{
    Rigidbody2D rigidbody2D;
    public RockerIcon rock;
    // Start is called before the first frame update
    void Start()
    {
        rigidbody2D = GetComponent<Rigidbody2D>();
        transform.GetComponent<Image>().sprite = Resources.Load<Sprite>("Icon/" + ZhanDouController.Instance.leftName);
    }

    // Update is called once per frame
    void Update()
    {
        float x = Input.GetAxis("Horizontal");
        float y = Input.GetAxis("Vertical");
        Vector2 dir = new Vector2(x, y).normalized;
        rigidbody2D.velocity = dir * 500f;

        float x1= rock.Mover("Horizontal");
        float y1= rock.Mover("Vertical");
        Vector2 dir1 = new Vector2(x1, y1).normalized;
        rigidbody2D.velocity = dir1 * 500f;
        if (x < 0||x1<0)
        {
            transform.GetComponent<Image>().sprite = Resources.Load<Sprite>("Icon/" + ZhanDouController.Instance.leftName);
        }
        else if (x > 0||x1>0)
        {
            transform.GetComponent<Image>().sprite = Resources.Load<Sprite>("Icon/" + ZhanDouController.Instance.righrName);
        }

    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
        ZhanDouController.Instance.GetBean(collision.collider.tag);
        if (collision.collider.tag == "big"|| collision.collider.tag == "small")
        {
            Destroy(collision.collider.gameObject);
        }
        if (collision.collider.tag == "gw1" )
        {
        print(BagCtrl.Instance.m_BagModel.shopPlayDataS);
            transform.GetComponentInChildren<Slider>().value += 0.05f;
        }
        if (collision.collider.tag == "gw2")
        {
            transform.GetComponentInChildren<Slider>().value += 0.1f;
        }
        if (collision.collider.tag == "boss")
        {
            transform.GetComponentInChildren<Slider>().value += 0.5f;
        }
    }
}
